#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

int main() {
    const char *fifo = "myfifo";
    int fd;

    mkfifo(fifo, 0666);

    fd = open(fifo, O_RDWR);
    if (fd == -1) {
        printf("Failed to open named pipe for writing\n");
        return -1;
    }

    const char *message = "Hello from Process A!\n";
    ssize_t message_len = strlen(message);
/*
      bytes_written = write(fd, message, message_len);
      if (bytes_written == -1) {
          printf("Failed to write to named pipe\n");
      } else {
          //printf("Data written to named pipe: %s\n", message);
          printf("read:%d\n", bytes_writtenessage_len);
      }
      */
    ssize_t bytes_written = 0;
    char res[1024] = {0};
    int rc  = 0;
    while (1) {
      rc = read (fd, res, sizeof (res));
      if (rc > 0) {
          printf("read:%d\n", rc);
      }
      sleep (1);
    }
    close(fd);
    return 0;
}

